<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      #clock {
        display: flex;
        width: 371px;
        height: 157px;
        background: url(./clock/LED.png) no-repeat;
        justify-content: center;
      }

      #clock > div {
        width: 18%;
        color: white;
        display: flex;
        justify-content: center;
        align-items: center;
      }
      #clock > div img {
        width: 50%;
      }
    </style>
  </head>
  <body>
    <div id="clock">
      <div id="elH">
        <img src="./clock/countdown0.png" />
        <img src="./clock/countdown0.png" />
      </div>
      <div>
        <img src="./clock/dot.png" />
      </div>
      <div id="elM">
        <img src="./clock/countdown0.png" />
        <img src="./clock/countdown0.png" />
      </div>
      <div>
        <img src="./clock/dot.png" />
      </div>

      <div id="elS">
        <img src="./clock/countdown0.png" />
        <img src="./clock/countdown0.png" />
      </div>
    </div>
    <script>
      function imgClock(num) {
        if (num < 10) {
          return `<img src="./clock/countdown0.png" /><img src="./clock/countdown${num}.png" />`;
        } else {
          const str = String(num);
          return `<img src="./clock/countdown${str[0]}.png" /><img src="./clock/countdown${str[1]}.png" />`;
        }
      }

      setInterval(() => {
        // 获取时分秒
        const d = new Date();
        const dh = d.getHours();
        const dm = d.getMinutes();
        const ds = d.getSeconds();
        // // 将时分秒设置到dom，添加前导0
        elH.innerHTML = imgClock(dh);
        elM.innerHTML = imgClock(dm);
        elS.innerHTML = imgClock(ds);
      }, 1000);
    </script>
  </body>
</html>
